package net.sf.calibur.test.tree;

import java.util.Stack;
import java.util.concurrent.atomic.AtomicLong;

public class Traveler {
	public static void main(String[] args) throws Exception {
		int val = 0;
		TreeNode root = new TreeNode(0);
		
		TreeNode n11 = new TreeNode(root, 11);
		TreeNode n12 = new TreeNode(root, 12);
		TreeNode n13 = new TreeNode(root, 13);
		
		TreeNode n111 = new TreeNode(n11, 111);
		TreeNode n112 = new TreeNode(n11, 112);
		
		TreeNode n131 = new TreeNode(n13, 131);
		
		Traveler traveler = new Traveler();
		traveler.travel(root);
	}
	
	AtomicLong TICK = new AtomicLong(0);
	public void travel(TreeNode root) {
		Stack<TreeNode> stack = new Stack<TreeNode>();
		stack.push(root);
		TreeNode curr;
		long tick = TICK.incrementAndGet();
		
		travelBranch(root, tick);
	}
	
	public boolean travelBranch(TreeNode branch, long tick) {
		for (TreeNode child : branch.getChildren()) {
			travelBranch(child, tick);
		}
		
		branch.perform(tick);
		return true;
	}
}
